package main

import (
	"fmt"
	"time"

	"github.com/pkg/profile"
)

//内存泄露
//https://mp.weixin.qq.com/s/KSBdPkkvonSES9Z9iggElg
//go run main.go
//go tool pprof -http=:8000 mem.pprof
func main04() {
	stopper := profile.Start(profile.MemProfile, profile.ProfilePath("."))
	defer stopper.Stop()

	ch := make(chan int, 30)

	go func() {
		in := 1
		for {
			ch <- in
			in++
		}
	}()

	for {
		select {
		case <-ch:
			//fmt.Println(v)
			//time.Sleep(time.Second)
			continue
		case <-time.After(time.Minute * 3):
			fmt.Println("现在是：%v，我脑子进煎鱼了", time.Now())
		}
	}
}

func main() {
	stopper := profile.Start(profile.CPUProfile, profile.ProfilePath("."))
	defer stopper.Stop()

	ch := make(chan int, 30)

	go func() {
		in := 1
		for {
			ch <- in
			in++
		}
	}()

	t := time.NewTimer(time.Minute * 3)
	defer t.Stop()
	for {
		select {
		case v := <-ch:
			fmt.Println(v)
			//time.Sleep(time.Second)
			continue
		case <-t.C:
			fmt.Println("现在是：%v，我脑子进煎鱼了", time.Now())
		}
	}
}
